package vn.edu.ptithcm.pim.dao;

import vn.edu.ptithcm.pim.dom.Department;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

@SuppressWarnings("rawtypes")
public class DepartmentDao extends HibernateDaoSupport {

	public void save(Department Department) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().save(Department);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void saveOrUpdate(Department Department) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().saveOrUpdate(Department);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void lock(Department Department) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().lock(Department, LockMode.NONE);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void delete(Department Department) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().delete(Department);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Department merge(Department Department) {
		try {
			return (Department) getHibernateTemplate().merge(Department);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Department findById(java.lang.Long id) {
		try {
			return (Department) getHibernateTemplate()
					.get(Department.class, id);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List findByExample(Department Department) {
		try {
			return getHibernateTemplate().findByExample("Department",
					Department);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List getAll() {
		try {
			return getHibernateTemplate().loadAll(Department.class);
		} catch (RuntimeException re) {
			throw re;
		}
	}
}
